﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.ViewModels.QueryViewModel>" %>
<%@ Import Namespace="dbPoll_Application.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Query
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>  
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

    <div class="pageHeadingContainer"><h2 class="pageHeading">Query</h2></div>
    <div id="contentContainer">
    <% Html.EnableClientValidation(); %>
    <div id="enterTimes">
        <p>Enter the time frames for filtering questions.</p>
        <% using (Html.BeginForm("Index", "Query", FormMethod.Post, new { @id = "queryForm" }))
            { %>
        <table>
            <tr>
            <script type="text/javascript">
                $(document).ready(function() {
                    $(".datepicker").datetimepicker({ dateFormat: 'dd/mm/yy', ampm: true });
                });
            </script>
                <td>Start date:</td><td><input name="startTime" type="text" class="datepicker" value="<%= Model.startTime.ToString("dd/MM/yyyy hh:mm tt") %>" readonly="readonly" /></td>
                <td>End date:</td><td><input name="endTime" type="text" class="datepicker" value="<%= Model.endTime.ToString("dd/MM/yyyy hh:mm tt") %>" readonly="readonly" /></td>
                <td>Poll Creator:</td><td><%= Html.DropDownListFor(m => m.selectedPollCreator.UserName, new SelectList(Model.allPollCreators, "UserName", "UserName", Model.selectedPollCreator.UserName)) %></td>
                <td><input type="submit" value="Search" /></td><td><%= Html.ValidationMessageFor(m => m.startTime) %><br /><%= Html.ValidationMessageFor(m => m.endTime) %></td>
            </tr>
        </table>
        <% } %>
    </div>
    <table class="questions">
    <thead>
    <tr>
    <th class="questionCol">Question</th>
    <th class="questionTypeCol">Type</th>
    <th class="questionTimeCol">Created Time</th>
    <th class="questionDelCol"></th>
    </tr>
    </thead>
    <script type="text/javascript">
        $(document).ready(function() {
            var url = '<%= Url.Action("DeleteQuestion", "Question") %>';
            $(".questionDel").click(function() {
                $.post(
                url, {
                    content: $(this).attr('id')
                },
                function(data) {
                    $('#questionRow' + data.value).hide();
                }
            )
            });
        });
    </script>
    <% foreach (var item in Model.questions)
       { %>
    <tr id="questionRow<%= item.question.questionID %>">
    <td class="questionCol"><%= Html.ActionLink(item.question.question.CropAndTrail(48, "..."), "Edit" + item.question.type, "Question", new { questionID = item.question.questionID, questionNumber = item.question.questionNumber, pollID = item.poll.pollID, pollName = item.poll.name }, null)%></td>
    <td class="questionTypeCol"><%= (item.question.type == dbPoll_Application.Models.QuestionType.Alphanumeric || item.question.type == dbPoll_Application.Models.QuestionType.Numeric) ? "Short-Answer" : "Multiple-Choice"%></td>
    <td class="questionTimeCol"><%= item.question.creationTime.ToString("dd/MM/yyyy hh:mm tt") %></td>
    <td class="questionDelCol"><input type="button" value="Delete" id="questionDel<%= item.question.questionID %>" class="questionDel"/></td>
    </tr>
    <% } %>
    </table>
    </div>    
</asp:Content>
